#include <iostream>
#include <fstream>
#include "user.pb.h"

using namespace std;
using namespace user;

void PrintUserInfo(const UserList& userList) {
    cout << " ----------- 用户信息 -----------" << endl;
    for (int i = 0; i < userList.users_size(); ++i) {
        const User& user = userList.users(i);
        cout << "用户名: " << user.name() << endl;
        cout << "邮箱: " << user.email() << endl;
        
        // 打印文章信息（如果有的话）
        if (user.article_list().articles_size() > 0) {
            cout << "文章列表: " << endl;
            for (int j = 0; j < user.article_list().articles_size(); ++j) {
                const Article& article = user.article_list().articles(j);
                cout << "  标题: " << article.title() << endl;
                cout << "  内容: " << article.content() << endl;
            }
        }
        cout << endl;
    }
}

int main(int argc, char* argv[]) {
    if (argc != 2) {
        cout << "Usage: " << argv[0] << " <filename>" << endl;
        return -1;
    }

    // 读取文件
    ifstream ifs(argv[1], ios::binary);
    if (!ifs) {
        cout << "Failed to open file: " << argv[1] << endl;
        return -1;
    }

    UserList userList; // 使用 UserList
    if (!userList.ParseFromIstream(&ifs)) {
        cout << "Failed to parse file: " << argv[1] << endl;
        return -1;
    }

    PrintUserInfo(userList);

    ifs.close();
    return 0;
}
